package cn.bdqn.controller;

import cn.bdqn.entity.Product;
import cn.bdqn.service.ProductService;
import cn.bdqn.utils.ResultVoUtil;
import cn.bdqn.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 郑大仙丶
 * @date 2018-12-31 16:47
 */
@RestController
@RequestMapping("/product")
public class ProductController {

    @Autowired
    private ProductService productService;


    /*
    查询全部商品
       {
			code:200,
			message:成功,
			data:[
				{
					id:1,
					productName:"汤圆"
				},
				{
					id:2,
					productName:"元宵"
				},
				..
			]
		}
     */

    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public ResultVo findAll(){
        List<Product> productList = productService.findAll();

        return ResultVoUtil.success(productList);
    }

    /*
    查询商品库存
    ``
    路径
    GET		/InSystem/product/findProductQuantity/{id}
    参数
        无
    ``
    响应数据
        成功
            {
                code:200,
                message:成功,
                data:16
            }
     */
    @RequestMapping(value = "/findProductQuantity/{id}",method = RequestMethod.GET)
    public ResultVo findProductQuantity(@PathVariable Integer id){
        Integer quantity = productService.findQuantityById(id);
        return ResultVoUtil.success(quantity);
    }

}
